package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysUseRecord2;
import com.ruoyi.system.service.ISysUseRecord2Service;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备使用记录Controller
 * 
 * @author 胡化敏
 * @date 2020-06-22
 */
@RestController
@RequestMapping("/record2")
public class SysUseRecord2Controller extends BaseController
{
    @Autowired
    private ISysUseRecord2Service sysUseRecord2Service;

    /**
     * 查询设备使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUseRecord2 sysUseRecord2)
    {
        startPage();
        List<SysUseRecord2> list = sysUseRecord2Service.selectSysUseRecord2List(sysUseRecord2);
        return getDataTable(list);
    }

    /**
     * 导出设备使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:export')")
    @Log(title = "设备使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody  SysUseRecord2 sysUseRecord2) throws IOException
    {
        List<SysUseRecord2> list = sysUseRecord2Service.selectSysUseRecord2List(sysUseRecord2);
        ExcelUtil<SysUseRecord2> util = new ExcelUtil<SysUseRecord2>(SysUseRecord2.class);
        util.exportExcel(response, list, "record2");
    }

    /**
     * 获取设备使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(sysUseRecord2Service.selectSysUseRecord2ById(recordId));
    }

    /**
     * 新增设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:add')")
    @Log(title = "设备使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUseRecord2 sysUseRecord2)
    {
        return toAjax(sysUseRecord2Service.insertSysUseRecord2(sysUseRecord2));
    }

    /**
     * 修改设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:edit')")
    @Log(title = "设备使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUseRecord2 sysUseRecord2)
    {
        return toAjax(sysUseRecord2Service.updateSysUseRecord2(sysUseRecord2));
    }

    /**
     * 删除设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('jdzx:record2:remove')")
    @Log(title = "设备使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(sysUseRecord2Service.deleteSysUseRecord2ByIds(recordIds));
    }
}
